package com.pay.alipay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pay.alipay.mapper.OrderMapper;
import com.pay.alipay.pojo.Order;
import com.pay.alipay.service.OrderService;
import com.pay.alipay.utils.StringUtils;
import com.pay.alipay.utils.SysConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
@Autowired
private OrderMapper orderMapper;
    /**
     * 创建订单
     * @return
     */
    @Override
    public Order createOrder() {
       //1.生成订单编号
        Order order=new Order();
        order.setOrderNo(StringUtils.createOrderNum());
        order.setSubject("测试数据11dddddd");
        order.setStatus(SysConstant.WAIT_BUYER_PAY);
        order.setTotalAmount("100.31");
        order.setCreateTime(new Timestamp(new Date().getTime()));
        order.setUpdateTime(new Timestamp(new Date().getTime()));
        orderMapper.insert(order);
        System.out.println(order);
        return order;
    }
//根据订单编号获取订单
    @Override
    public Order getByTradeNo(String outTradeNo) {
        //定义查询条件
        QueryWrapper<Order> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("order_no",outTradeNo);
        Order order=  orderMapper.selectOne(queryWrapper);
        return order;
    }
//更新订单信息
    @Override
    public void updateOrderStatus(Order order, String tradeSuccess) {
         order.setStatus(tradeSuccess);
         System.out.println(tradeSuccess);
         order.setUpdateTime(new Timestamp(new Date().getTime()));
         orderMapper.updateById(order);
    }
}
